<?php

/**
 * autentificacion actions.
 *
 * @package    proyectoMOD2
 * @subpackage autentificacion
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 12479 2008-10-31 10:54:40Z fabien $
 */
class autentificacionActions extends sfActions
{
  public function executeIndex()
  {

  }
  
  public function executeListarlogin($peticion)
  {  
  	if($this->getUser()->getAttribute('login')=='admin') $entrar=true;
    else $entrar=false;
    if ($entrar)
    {  
		    $c= new Recurso();
     		$this->tabla= $c->getLogins();		
	}else{
	$this->redirect('proyecto/error');
	}		
  }
  
  public function executeAsignarlogin($peticion)
  { 
  	$this->login_erroneo=$peticion->getParameter('login_erroneo');
	$this->password_erroneo=$peticion->getParameter('password_erroneo');
   	if($this->getUser()->getAttribute('login')=='admin') $entrar=true;
    else $entrar=false;
    if ($entrar)
    {  
  	$this->id=$peticion->getParameter('RadioGroup1');
	$asignado = new Recurso();
	$this->nombre=$asignado ->getNombreCompleto($peticion->getParameter('RadioGroup1'));	
	}else{
	$this->redirect('proyecto/error');
	}	
  }
  
  public function executeProcesar($peticion)
  {  
  	 $i=0;
  	  if ($peticion->getParameter('login')=="") 	  
	  {
	  	$this->login_erroneo="<label>*ERROR este campo es obligatorio</label>";
	  	$i=$i+1;
	  }
	  if ($peticion->getParameter('password')=="") 	  
	  {
	  	$this->password_erroneo="<label>*ERROR este campo es obligatorio</label>";
	  	$i=$i+1;
	  }
	  if ($peticion->getParameter('password')!=$peticion->getParameter('password1')) 	  
	  {
	  	$this->password_erroneo="<label>*ERROR password erroneo</label>";
	  	$i=$i+1;
	  }
	  $c= new Recurso();
	  if ($c->ExisteLogin($peticion->getParameter('login'),$peticion->getParameter('id'))>=1)
	  {
	  	$this->login_erroneo="<label>*ERROR ese login ya esta en uso </label>";
		$i=$i+1;
	  }
	  if($i==0)
	  { 
		$asignado = new Recurso();
		$asignado ->setLogin($peticion->getParameter('login'));
		$asignado ->setPassword($peticion->getParameter('password'));	
		$asignado ->UpdateLogin($peticion->getParameter('id'));
		$this->redirect('autentificacion/listarlogin');
	 }else
	 {
	 	$this->getRequest()->setParameter('RadioGroup1',$peticion->getParameter('id'));
	 	$this->getRequest()->setParameter('login_erroneo',$this->login_erroneo);
		$this->getRequest()->setParameter('password_erroneo',$this->password_erroneo);		
		$this->forward('autentificacion','asignarlogin');	
	 }		
	
  }
  
   public function executeBienvenida($peticion)
  {
  }
  
   public function executeSalir($peticion)
  {
    $this->getUser()->getAttributeHolder()->clear();
  	$this->redirect('autentificacion/bienvenida');	
  }
  
   public function executeValidacion($peticion)
  {
	$e = new Recurso();	
	$e->setLogin($peticion->getParameter('login'));
	$e->setPassword($peticion->getParameter('password'));
	if ($peticion->getParameter('volver')==true)
	{
	$e->setLogin($this->getUser()->getAttribute('login'));
	$e->setPassword($this->getUser()->getAttribute('password'));	
	}

	$this->existe=$e->Existe();
	if ($this->existe>-1)
	{		
			$c = new Criteria();
			$c->add(RecursoPeer::ID, $this->existe);
			$this->setVar('existe', RecursoPeer::doCount($c));
			$this->setVar('recurso', RecursoPeer::doSelectOne($c));
		    $c= new Recurso();
     		$this->tabla= $c->getMisProyectos($this->recurso->getId());
			$this->tabla1= $c->getMisActividades($this->recurso->getId());
			$this->getUser()->setAttribute('id', $this->recurso->getId());
			$this->getUser()->setAttribute('login', $peticion->getParameter('login',$this->getUser()->
			getAttribute('login')));
			$this->getUser()->setAttribute('password', $peticion->getParameter('password',$this->
			getUser()->getAttribute('password')));
	}
  }
}
